﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class EditCategory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Label10.Visible = false;
            LoadData();
            Button2.Attributes.Add("onclick", "confirm('Are you sure you want to proceed?')");
         }
      
      
    
      
    }

    private void LoadData()
    {
        string username = Request.QueryString["id"].ToString();
        ManagementCustomer m = new ManagementCustomer();
        ORANGE_PROJECTModel.Customer c = (ORANGE_PROJECTModel.Customer)m.GetEditCustomer(username);
        txtID.Text = username;
        txtName.Text = c.CustomerName;
        txtPhone.Text = c.Phone;
        txtEmail.Text = c.Email;
        txtAddress.Text = c.Address;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
      
        string username = Request.QueryString["id"].ToString();
        ManagementCustomer m = new ManagementCustomer();
        ORANGE_PROJECTModel.Customer c = (ORANGE_PROJECTModel.Customer)m.GetEditCustomer(username);
        string password=c.Password;
        if(txtPass0.Text!="")
        {
            password = txtPass0.Text;
        }
        if (m.UpdateCustomer(txtID.Text,txtName.Text,txtPhone.Text,txtEmail.Text,txtAddress.Text,password))
        {
            Label10.Visible = true;
            Label10.Text = "<span style='color:green;font-weight: bold;'>Update Succerfully :)</span>";
        }
        else
        {
            Label10.Visible = true;
            Label10.Text = "<span style='color:red;font-weight: bold;'>Update Failed (:</span>";
        }
        
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string id = Request.QueryString["id"].ToString();
        ManagementCustomer m = new ManagementCustomer();
        if (m.DeleteCustomer(id))
        {
            Response.Redirect("ManagementCustomer.aspx");
        }
    }
}